package com.heima.admin.controller.v1;

import com.heima.admin.service.AdUserLoginService;
import com.heima.apis.admin.LoginControllerApi;
import com.heima.model.admin.dtos.AdUserDto;
import com.heima.model.admin.pojos.AdUser;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
@Api(tags = "用户登录管理")
public class AdUserLoginController implements LoginControllerApi {

    //注入UserService层对象
    @Autowired
    private AdUserLoginService adUserService;


    @PostMapping("/in")
    @Override
    @ApiOperation(value = "用户登录")
    public ResponseResult login(@RequestBody AdUserDto dto) {
        System.out.println("dto = " + dto);
        return adUserService.login(dto);
    }


    /**
     * 注册功能
     * @param user 用户实体对象
     * @return
     */
    @PostMapping("/register")
    @Override
    @ApiOperation(value = "注册用户")
    public ResponseResult login(AdUser user) {
        return adUserService.register(user);
    }
}
